As one of methods for encoding video information at a target bitrate, there is a 2-pass encoding scheme of executing encoding once to calculate a feature of video, obtaining an allocation bitrate of each picture based thereon, and then performing encoding again, or a multi-pass encoding scheme for repeatedly performing it a plurality of times. Since these schemes are capable of appropriately distributing bitrates to respective pictures based on the result of the encoding executed once, efficient encoding can be achieved.
Even if the entire allocation bitrate of each picture is allocated based on the result of the first encoding, there is an error between an actually generated bitrate and the allocation bitrate. Accordingly, in order for a stream to come within a target size, it is necessary to incorporate an error bitrate into an allocation bitrate of a next picture to correct the errors one at a time.
A method for allocating a constant bitrate R to a plurality of pictures and incorporating an error bitrate into the constant bitrate R as cited in Non-Patent Document 1 below is widely used when CBR (constant bit rate) encoding is performed in a single pass.
On the other hand, when this CBR encoding method is applied to multi-pass encoding in which an allocation bitrate of each picture is previously determined, since the allocation bitrate of each picture is previously determined, a process for allocating a constant bitrate to a plurality of pictures is unnecessary. Accordingly, when this CBR encoding method is applied to multi-pass encoding, correction is performed by adding an error bitrate generated upon encoding of each picture to an allocation bitrate of a next picture.
FIG. 12 shows an example of a flowchart in accordance with a background art in which after an allocation bitrate and a feature of each picture have been calculated based on the result of the first encoding, the above method (a method for performing correction by adding an error bitrate generated upon encoding of each picture to an allocation bitrate of a next picture) is used.
In the background art, first, in step S501, an error bitrate and a picture number n are initialized to 0 as an initialization process, as shown in this flowchart.
In step S502, an nth picture is then encoded at a previously given allocation bitrate.
That is, an encoding process shown in a flowchart of FIG. 13 is executed. A quantization width is calculated from an allocation bitrate of the nth picture and a feature of the nth picture (step S601), a prediction residual is calculated (step S602), a discrete cosine transform (DCT) is applied (step S603), and a DCT coefficient is quantized (step S604). An encoded stream is then generated by variable length encoding (step S605). On the other hand, the quantized DCT coefficient is subjected to dequantization (step S606) and an inverse discrete cosine transform (IDCT) (step S607) to produce a decoded image of the prediction residual, which is added to a predicted image to generate a decoded image (step S608).
In step S503, a determination is then made as to whether or not all frames (all pictures) have been encoded, and when all the frames have been encoded, the process is terminated, and when all the frames have not been encoded, the following processes are executed.
That is, in the subsequent step S504, an error bitrate is calculated from a difference between the allocation bitrate and an actual bitrate generated upon encoding. In the subsequent step S505, the error bitrate is added to an allocation bitrate of a next picture to update the allocation bitrate of the next picture. In the subsequent step S506, a subject to be processed is shifted to the next picture, the flow returns to the process of step S502, and the above procedure is repeatedly performed.
Through the above process, the errors between the allocation bitrates and the generated bitrates are corrected one at a time, thereby an encoded stream close to a target file size can be obtained.
FIG. 14 illustrates an apparatus configuration of a conventional video encoding apparatus for executing the processes of the flowcharts shown in FIGS. 12 and 13.
As shown in FIG. 14, the conventional video encoding apparatus for executing the processes of the flowcharts shown in FIGS. 12 and 13 is provided with an allocation bitrate storage unit 101, two adders 102 and 111, two subtractors 103 and 106, a feature storage unit 104, a quantization width calculation unit 105, a DCT unit 107, a quantization unit 108, a dequantization unit 109, an IDCT unit 110, a decoded image storage buffer 112, a predicted image generation unit 113, and a variable length encoding unit 114.
The allocation bitrate storage unit 101 stores initial values of allocation bitrates of respective pictures and outputs them to the adder 102 one at a time. The adder 102 adds an initial value of an allocation bitrate output by the allocation bitrate storage unit 101 to an error bitrate output by the subtractor 103 to calculate and output an allocation bitrate of the picture to be encoded. The subtractor 103 calculates a difference between the allocation bitrate output by the adder 102 and a generated bitrate output by the variable length encoding unit 114 to calculate and output an error bitrate of a picture that has been encoded. The feature storage unit 104 stores features of the respective pictures obtained upon the first-pass encoding, and outputs them to the quantization width calculation unit 105 one at a time. The quantization width calculation unit 105 calculates and outputs a quantization width of the picture to be encoded from a feature output by the feature storage unit 104 and the allocation bitrate output by the adder 102.
The subtractor 106 calculates a difference between an input image and a predicted image output by the predicted image generation unit 113 to generate and output a prediction residual. The DCT unit 107 applies DCT to the prediction residual output by the subtractor 106. The quantization unit 108 applies quantization to each DCT coefficient output by the DCT unit 107 using the quantization width output by the quantization width calculation unit 105. The dequantization unit 109 applies dequantization to a quantization value output by the quantization unit 108 using the quantization width output by the quantization width calculation unit 105. The IDCT unit 110 applies IDCT to a dequantized coefficient output by the dequantization unit 109. The adder 111 adds a prediction residual decoded signal output by the IDCT unit 110 to the predicted image output by the predicted image generation unit 113 to generate a decoded image, and outputs it to the decoded image storage buffer 112. The decoded image storage buffer 112 stores the decoded image output by the adder 111. The predicted image generation unit 113 generates and outputs the predicted image based on the decoded image stored in the decoded image storage buffer 112. The variable length encoding unit 114 applies variable length encoding to the quantized DCT coefficient output by the quantization unit 108, and outputs an encoded stream.
The conventional video encoding apparatus executes the processes of the flowcharts shown in FIGS. 12 and 13 using the configuration as shown in FIG. 14.
It is noted that a CBR rate technique that is a basis of a method described in Non-Patent Document 1 is explained in Patent Document 1 below in which Document Name (ISO/IEC JTC/SC29/WG11: “Test Model 5”, 1993) is cited. However, the invention described in this document is merely a technique within the framework of CBR even though a response to the bitrate variation is higher in comparison with the method described in Non-Patent Document 1. Accordingly, when the invention described in this document is applied to multi-pass encoding, correction is performed by adding an error bitrate generated upon encoding of each picture to an allocation bitrate of a next picture, as in the case where the method described in Non-Patent Document 1 is applied.